package com.hhw.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hhw.entity.BaseDict;
import com.hhw.entity.Customer;
import com.hhw.service.BaseDictService;
import com.hhw.service.CustomerService;
import com.hhw.service.CustomerServiceImp;


      
@Controller
public class CustomerController {
	
	@Autowired
	private CustomerService cs;
	
	
	
	
//		查询全部客户信息
	@RequestMapping("selectAllCustomer")
	public String customer(Model model,
			@RequestParam(required=true,defaultValue="1")Integer pageNum,
			@RequestParam(required=true,defaultValue="20")Integer pageSize){
		PageHelper.startPage(pageNum,pageSize); 
		List<Customer> list=cs.selectAllCustomer();
		PageInfo<Customer> page=new PageInfo<Customer>(list);
		model.addAttribute("page", page);
		return "customer";
	}
	
	
	//根据ID查询客户信息
	@RequestMapping("toupdateCustomer")
	public String toupdateCustomer(Integer id,Model model){
		Customer customer=this.cs.SelectCustomerById(id);
		model.addAttribute("cid", id);
		return "updatecustomer";
	}
	
	@RequestMapping("doupdateCustomer")
	public String doupdateProduct(Customer customer,Model model){
		 boolean result=this.cs.updateCustomer(customer);
		 if(result){
			 return "forward:selectAllCustomer";
		 }
		 return "updatecustomer";	
		}
	
	
	
	
			/*	@RequestMapping("edit")
				@ResponseBody
				public Customer edit(Integer id){
					Customer customer = cs.SelectCustomerById(id);
					return customer;
				}
				@RequestMapping("update")
				@ResponseBody
				public String update(Customer customer){
					String msg = "1";
					try {
						cs.updateCustomer(customer);
						msg = "0";
					} catch (Exception e) {
						e.printStackTrace();
					}
					return msg;
				}*/
	
}
